<?php 
	$yhendus=new mysqli("localhost", "if13", "ifikad", "if13_leetussa");
	?>
<!doctype html>
<html>
  <head>
    <title>Etteasted</title>
    <style type="text/css">
	#menyykiht{
         float: left;
         padding-right: 30px;
       }
       #sisukiht{
         float:left;
       }
       #jalusekiht{
         clear: left;
       }
    </style>
	<meta charset="utf-8" />
  </head>
  <body>
    <div id="menyykiht">
        <h2>Etteasted</h2>
        <ul>
          <?php
             $kask=$yhendus->prepare(
			   "SELECT id, nimi, aeg  FROM etteaste");
             $kask->bind_result($id, $nimi, $aeg);
             $kask->execute();
             while($kask->fetch()){
               echo "<li><a href='?id=$id'>".
                     htmlspecialchars($nimi)."</a></li>";
             }
          ?>
        </ul>
    </div>
    <div id="sisukiht">
		<?php
			if(isSet($_REQUEST["id"])){
            $kask=$yhendus->prepare("SELECT id, nimi, aeg FROM etteaste WHERE id=?");
            $kask->bind_param("i", $_REQUEST["id"]); 
            $kask->bind_result($id, $nimi, $aeg);
            $kask->execute();
			}
            if($kask->fetch()){
              echo "<h2>".htmlspecialchars($nimi)."</h2>";
              echo "Esinemisaeg: ";
			  echo htmlspecialchars($aeg);
			}
        ?>
    </div>
    <div id="jalusekiht">
     <a href="index.php">Avalehele</a>
    </div>
  </body>
</html>
<?php
  $yhendus->close();
?>